/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-06-30 16:44:23
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-07-01 14:13:36
 * @FilePath: \keep_motion_api\models\specil.model.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// 用户画像模型
const userProfileSchema = new Schema({
  user_id: { 
    type: Schema.Types.ObjectId, 
    ref: 'User',
    required: true,
    unique: true 
  },
  sport_preference: [{
    type: Schema.Types.ObjectId, 
    ref: 'SportType'
  }],
  diet_habit: String,
  fitness_goal: String,
  behavior_tags: [String],
  last_update: Date,
  interest_tags: [String],
  activity_level: {
    type: String, 
    enum: ["low", "medium", "high"]
  },
  purchase_power: Number,
  course_preferences: [{
    type: String,
    enum: ["fitness", "yoga", "strength", "cardio", "nutrition"]
  }],
  learning_style: {
    type: String,
    enum: ["visual", "auditory", "kinesthetic"]
  }
});

userProfileSchema.statics.getProfiles = async function (user_id) {
  return await this.find({ user_id });
}
userProfileSchema.statics.getStats = async function (user_id) {
  return await this.find({ user_id });
}
userProfileSchema.statics.syncProfiles = async function (user_id, profile) {
  return await this.findOneAndUpdate({ user_id }, profile, { upsert: true });
}

module.exports = mongoose.model('UserProfile', userProfileSchema);
